package com.zzt.pagehelp.util

/**
 * @author: zeting
 * @date: 2022/10/26
 *
 */
sealed class LoadState(val noMore: Boolean) {
    /**
     * 无加载状态，可作为加载完成的状态处理
     */
    class NotLoading(noMore: Boolean) : LoadState(noMore) {
        override fun toString(): String {
            return "NotLoading(noMore=$noMore)"
        }

        override fun equals(other: Any?): Boolean {
            return other is NotLoading &&
                    noMore == other.noMore
        }

        override fun hashCode(): Int {
            return noMore.hashCode()
        }
    }

    /**
     * 加载中状态
     */
    object Loading : LoadState(false) {
        override fun toString(): String {
            return "Loading(noMore=$noMore)"
        }

        override fun equals(other: Any?): Boolean {
            return other is Loading &&
                    noMore == other.noMore
        }

        override fun hashCode(): Int {
            return noMore.hashCode()
        }
    }

    /**
     * 加载异常状态，在获取数据过程中出现异常时回调
     */
    class Error(
        val error: Throwable
    ) : LoadState(false) {
        override fun equals(other: Any?): Boolean {
            return other is Error &&
                    noMore == other.noMore &&
                    error == other.error
        }

        override fun hashCode(): Int {
            return noMore.hashCode() + error.hashCode()
        }

        override fun toString(): String {
            return "Error(noMore=$noMore, error=$error)"
        }
    }
}